<?php
namespace app\index\controller;
use think\Db;
use think\Controller;
use  think\Request;

class Jiaose extends Base
{
    
	public function Index(){
		
		
		
		
		
		 return view();
	}
	
	
	
	function Add(){
		
		$request = Request::instance();
	
		
		if($request->isPost()){
				$data["id"] =$request->post('id');
				$data["jiaosename"] =$request->post('jiaosename');
				$data["backinfo"] =$request->post('backinfo');
				$data["quanxian"] =$request->post('quanxian');
				
				$data["state"] =$request->post('state');
				$data["aid"] =session("mid");
			
				
			if($data["id"]){
				
			
				
				if(db('sys_jiaose')->update($data)){
					
					  return ['status'=>200,'message'=>'修改成功'];
				}else{
					 return ['status'=>500,'message'=>'修改失败'];
				}
			}else{
				
			
			  if(db('sys_jiaose')->insertGetId($data)){
					 return ['status'=>200,'message'=>'添加成功'];
					
				}else{
					return ['status'=>500,'message'=>'添加失败'];
				}
			}
			
		}else{
			
			if($request->get('id')){
				$info =db('sys_jiaose')->where("id=".$_GET["id"])->find();
				$this->assign('info',$info);
				
			}
			
			
			$treelist = db('sys_menu')->where("parentid=0 and textstr!='超级管理' and textstr!='机构管理'")->select();
			foreach ($treelist as $key => &$value) {
				$id= $value["id"];
				$value["children"] = db('sys_menu')->where("parentid=".$id)->select();	
			}
			$this->assign('treelist',$treelist);
		
	
		
			
		}
		
		
	
	
		return view();
	}
	 public function GetJiaose(){
		$where="aid=".session("mid");
		$count =db('sys_jiaose')->where($where)->count();
		$first = $_GET["size"] * ($_GET["page"] -1);
		 
		$list = db('sys_jiaose')->where($where)->limit($first,$_GET["size"])->select();
		$obj["count"]=(int)($count/$_GET["size"])+1;
		$obj["allcount"]=$count;
		$obj["list"]=$list;
		return json($obj);
		
	}
	 public function GetJiaoseList(){
		 $request = Request::instance();
		
		 
		 $where="aid=".session("mid");
		$list = db('sys_jiaose')->where($where)->select();
	
		return json($list);
		
	}
	function Del(){
		$request = Request::instance();
		$id =$request->post('id');
		
		
		 
			$where = 'id='.$id;
		  
		   $list=db('sys_jiaose')->where($where)->delete();
		   if($list!==false) {
			 return ['status'=>200,'message'=>'删除成功'];
		   }else{
			  return ['status'=>500,'message'=>'删除失败'];
		   }
		
	}
}
